﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model Domain.Dto.ArticleInfoDto
<div id="divArticle">
    @using (Ajax.BeginForm("add", "article", new AjaxOptions()
    {
        HttpMethod = "post",
        OnBegin = "checkedAddForm",
        OnSuccess = "addSuccess",
        OnFailure = "addFailure"
    }))
    {
        <fieldset class="module width_full">
            @Html.Partial("_Form", Model)
        </fieldset> 
        <p>
            @{
        if (Html.HasUiPermission(this.ViewContext, "add"))
        {
                <input type="submit" value="添加" class='alt_btn module_margin' />
        }
            }
        </p>
    }
</div>
<script type="text/javascript">

    function checkedAddForm() {
        var res = true;
        if ($('#articleClass').val() == 0) {
            $('#articleClass').focus();
            alert("请选择分类");
            res = false;
            return res;
        }
        if ($('#Title').val() == "") {
            alert("标题不能为空");
            $('#Title').focus();
            res = false;
            return res;
        }
        return res;
    }

    function addSuccess(res) {
        if (res.success) {
            alert("添加成功");
            window.location.reload();
        }
        else {
            alert(res.message);
        }
    }

    function addFailure() {
        alert("添加失败了T_T！");
    }


    $(document).ready(function () {
        var select = $('#isNotExpired').attr('checked');
        isNotExpired(select);
        $('#isNotExpired').click(function (e) {
            select = $(this).attr('checked');
            isNotExpired(select);
        });
    });

    function isNotExpired(select) {
        if (select != undefined) {
            //$('#ExpiredDateTime_wrapper').addClass('t-state-disabled').attr('disabled', 'disabled');
            $('#ExpiredDateTime').attr('style', 'background:#939291;');
            $('#isNotExpired').val('1');
        }
        else {
            //$('#ExpiredDateTime_wrapper').removeClass('t-state-disabled').removeAttr('disabled');
            $('#ExpiredDateTime').attr('style', 'background:;');
            $('#isNotExpired').val('0');
        }
    }

</script>
